package com.shenzhen.horselive.adapter;

import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.viewholder.BaseViewHolder;
import com.shenzhen.horselive.R;
import com.shenzhen.horselive.beans.RechargeBean;

import org.jetbrains.annotations.NotNull;

import java.text.DecimalFormat;

public class PhoneRechargeAdapter extends BaseQuickAdapter<RechargeBean.DataBean, BaseViewHolder> {
    private int  selectPos = 0;
    private int  payType=1;//0蜂值，，1，，2微信和支付宝
    public PhoneRechargeAdapter(int layoutResId) {
        super(layoutResId);
    }

    @Override
    protected void convert(@NotNull BaseViewHolder baseViewHolder, RechargeBean.DataBean s) {
           baseViewHolder.setText(R.id.tv_money,s.getCardnum()+"元")
                   ;
           //优惠金额

          switch (payType)
          {
              case 0:
                  //蜂值
                  double  youhui = Double.parseDouble(s.getCardnum())*Double.parseDouble(s.getFzDiscounts());
                  baseViewHolder.setText(R.id.tv_real_money,"折扣价:"+fuckNumber(youhui)+"元");
                  break;
              default:
                  double  youhui1 = Double.parseDouble(s.getCardnum())*Double.parseDouble(s.getDiscounts());
                  baseViewHolder.setText(R.id.tv_real_money,"折扣价:"+fuckNumber(youhui1)+"元");
                  break;
          }
           if (baseViewHolder.getAdapterPosition()==selectPos)
           {
               //选中
               baseViewHolder.setBackgroundResource(R.id.item_liner,R.drawable.shape_recharge_unselector);
               baseViewHolder.setTextColorRes(R.id.tv_money,R.color.red_common);
               baseViewHolder.setTextColorRes(R.id.tv_real_money,R.color.red_common);

           }else
           {
               //未选中
               baseViewHolder.setBackgroundResource(R.id.item_liner,R.drawable.shape_item_recahrge);
               baseViewHolder.setTextColorRes(R.id.tv_money,R.color.color_3);
               baseViewHolder.setTextColorRes(R.id.tv_real_money,R.color.color_6);
           }


    }

    public   void   setSelectPos(int pos)
    {
        this.selectPos = pos;
        notifyDataSetChanged();
    }

    public int getSelectPos() {
        return selectPos;
    }

    public void setPayType(int payType) {
        this.payType = payType;
        notifyDataSetChanged();
    }

    //保留两位小数
    private   String  fuckNumber(double  num)
    {
        DecimalFormat   decimalFormat = new DecimalFormat("0.00");
        return decimalFormat.format(num);
    }



}
